package com.wbc.smartHome.web;

import com.github.pagehelper.PageInfo;
import com.wbc.smartHome.model.Commodity;
import com.wbc.smartHome.model.CommunityActivitiesLabel;
import com.wbc.smartHome.model.Result;
import com.wbc.smartHome.service.CommunityActivitiesLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping(path = "/api/CommunityActivitiesLabelCtl")
/*热门商品存取*/
@Api(tags = "社区活动标签模块")
public class CommunityActivitiesLabelController {


    @Autowired
    private CommunityActivitiesLabelService communityActivitiesLabelService;

    @ApiOperation("获取所有社区活动标签")
    @ApiResponses({
            @ApiResponse(code = 200 , message = "OK"),
            @ApiResponse(code = 500 , message = "系统异常")
    })
    @PostMapping(path = "getCommunityActivitiesLabelList")
    public Result getCommunityActivitiesLabelList(@RequestBody CommunityActivitiesLabel communityActivitiesLabel) {
        PageInfo<CommunityActivitiesLabel> communityLabelList = communityActivitiesLabelService.getCommunityActivitiesLabelList(communityActivitiesLabel);
        return new Result(200, "OK", communityLabelList);

    }

    @ApiOperation("添加社区活动标签")
    @ApiResponses({
            @ApiResponse(code = 200 , message = "OK"),
            @ApiResponse(code = 500 , message = "系统异常")
    })
    @PostMapping(path = "setCommunityActivitiesLabel")
    public Result setCommunityActivitiesLabel(@RequestBody CommunityActivitiesLabel communityActivitiesLabel,@RequestHeader("adminToken") String adminToken) {

        if (communityActivitiesLabel.getId()==null){
            communityActivitiesLabelService.setCommunityActivitiesLabel(communityActivitiesLabel,adminToken);
        }
        else {
            communityActivitiesLabelService.updateCommunityActivitiesLabel(communityActivitiesLabel, adminToken);
        }
        return new Result(200,"ok",null);
    }

    @ApiOperation("删除标签")
    @ApiResponses({
            @ApiResponse(code = 200 , message = "删除成功"),
            @ApiResponse(code = 500 , message = "系统异常")
    })
    @GetMapping(path = "delete")
    public Result delete(int id){
        communityActivitiesLabelService.delete(id);
        Result result = new Result(200, "删除成功", null);
        return result;
    }

    @ApiOperation("按照id获取标签")
    @ApiResponses({
            @ApiResponse(code = 200 , message = "删除成功"),
            @ApiResponse(code = 500 , message = "系统异常")
    })
    @GetMapping(path = "/getCommunityActivitiesLabelById")
    public Result getCommunityActivitiesLabelById(int id) {
        CommunityActivitiesLabel activitiesLabel = communityActivitiesLabelService.getCommunityActivitiesLabelById(id);
        Result result = new Result(200, "OK", activitiesLabel);
        return result;
    }

}
